package com;

import java.io.*;

public class Auth_Copy01 {

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
       String file = filepath.replaceAll("\\\\","\\\\\\\\");
       this.filepath = file;
    }

    private String filepath = "";

    // none ref
    public Auth_Copy01(){}

    public void Copy() {
        System.out.println(filepath);
        try {
            BufferedReader br = new BufferedReader(
                    new FileReader(filepath)
            );
            BufferedWriter  wr = new BufferedWriter(
                    new FileWriter(filepath.replaceAll(".txt","_success.txt"))
            );
            String s1 ="";
            Integer count = getFileLineNum(filepath);
            System.out.println(count);
            while((s1=br.readLine())!=null){
                count --;
                wr.write("https://hls.cntv.kcdnvip.com/asp/hls/main/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://hls.cntv.kcdnvip.com/asp/hls/450/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://hls.cntv.kcdnvip.com/asp/hls/850/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://hls.cntv.kcdnvip.com/asp/hls/1200/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls.cntv.kcdnvip.com/asp/enc/hls/main/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls.cntv.kcdnvip.com/asp/enc/hls/450/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls.cntv.kcdnvip.com/asp/enc/hls/850/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls.cntv.kcdnvip.com/asp/enc/hls/1200/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls.cntv.kcdnvip.com/asp/enc/hls/2000/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dh5.cntv.kcdnvip.com/asp/h5e/hls/main/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dh5.cntv.kcdnvip.com/asp/h5e/hls/450/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dh5.cntv.kcdnvip.com/asp/h5e/hls/850/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dh5.cntv.kcdnvip.com/asp/h5e/hls/1200/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dh5.cntv.kcdnvip.com/asp/h5e/hls/2000/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls2.cntv.kcdnvip.com/asp/enc2/hls/main/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls2.cntv.kcdnvip.com/asp/enc2/hls/450/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls2.cntv.kcdnvip.com/asp/enc2/hls/850/0303000a/3/default/"+s1+"/"+"\n");
                wr.write("https://dhls2.cntv.kcdnvip.com/asp/enc2/hls/1200/0303000a/3/default/"+s1+"/"+"\n");
                if (count != 0){
                wr.write("https://dhls2.cntv.kcdnvip.com/asp/enc2/hls/2000/0303000a/3/default/"+s1+"/"+"\n");
                }else {
                    wr.write("https://dhls2.cntv.kcdnvip.com/asp/enc2/hls/2000/0303000a/3/default/"+s1+"/");
                }
            };
            br.close();
            wr.close();
        } catch (Exception e){
            return;
        }
    }

    public static int getFileLineNum(String filePath) {
        try (LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(filePath))){
            lineNumberReader.skip(Long.MAX_VALUE);
            int lineNumber = lineNumberReader.getLineNumber();
            return lineNumber + 1;//实际上是读取换行符数量 , 所以需要+1
        } catch (IOException e) {
            return -1;
        }
    }
}
